package com.ruoyi.edit.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edit.domain.Ability;
import com.ruoyi.edit.service.IAbilityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 能力指标Controller
 * 
 * @author qiufeng
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/system/ability")
public class AbilityController extends BaseController
{
    private String prefix = "system/ability";

    @Autowired
    private IAbilityService abilityService;

    @RequiresPermissions("system:ability:view")
    @GetMapping()
    public String ability()
    {
        return prefix + "/ability";
    }

    /**
     * 查询能力指标列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ability ability)
    {
        startPage();
        List<Ability> list = abilityService.selectAbilityList(ability);
        return getDataTable(list);
    }

    /**
     * 导出能力指标列表
     */
    @Log(title = "能力指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ability ability)
    {
        List<Ability> list = abilityService.selectAbilityList(ability);
        ExcelUtil<Ability> util = new ExcelUtil<Ability>(Ability.class);
        return util.exportExcel(list, "能力指标数据");
    }

    /**
     * 新增能力指标
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存能力指标
     */
    @Log(title = "能力指标", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Ability ability)
    {

        return toAjax(abilityService.insertAbility(ability));
    }

    /**
     * 修改能力指标
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Ability ability = abilityService.selectAbilityById(id);
        mmap.put("ability", ability);
        return prefix + "/edit";
    }

    /**
     * 修改保存能力指标
     */
    @Log(title = "能力指标", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Ability ability)
    {
        return toAjax(abilityService.updateAbility(ability));
    }

    /**
     * 删除能力指标
     */
    @Log(title = "能力指标", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(abilityService.deleteAbilityByIds(ids));
    }
}
